/**
 * 
 */
package com.dsbridge.enrollment.web;

import java.util.Date;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.jsf.FacesContextUtils;

import com.dsbridge.enrollment.business.StudentBusinessService;
import com.dsbridge.enrollment.model.StudentsDTO;

/**
 * @author rithvik
 * 
 */
@ManagedBean
@RequestScoped
public class StudentController {

	private Date registrationDate;
	private String loginName;
	private String password;
	private String firstName;
	private String lastName;
	private String middleName;

	// Some Action needs to be Done.
	public String createStudent() {
		// You Call the Spring Business Services..
		// Call the Respective Methods.
		StudentsDTO studentsDTO = new StudentsDTO();
		studentsDTO.setFirstName(firstName);
		studentsDTO.setLastName(lastName);
		studentsDTO.setMiddleName(middleName);
		studentsDTO.setPassword(password);
		studentsDTO.setLoginName(loginName);
		studentsDTO.setRegistrationDate(new java.sql.Date(registrationDate
				.getTime()));
		ApplicationContext appContext = FacesContextUtils
				.getRequiredWebApplicationContext(FacesContext
						.getCurrentInstance());
		StudentBusinessService studentBusinessService = appContext
				.getBean(StudentBusinessService.class);
		int i = studentBusinessService.createStudent(studentsDTO);
		if (i > 0) {
			FacesContext.getCurrentInstance().addMessage(
					"StudentCreateMessage",
					new FacesMessage(FacesMessage.SEVERITY_INFO,
							"Student Created Succesfully", "D"));
			return "studentResponse";
		} else {
			return "studentError";
		}
	}

	public Date getRegistrationDate() {
		return registrationDate;
	}

	public void setRegistrationDate(Date registrationDate) {
		this.registrationDate = registrationDate;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getMiddleName() {
		return middleName;
	}

	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}
}
